package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.NormalRepayBean;
import com.yiwei.hdb.api.callback.NormalRepayContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class NormalRepayRequest extends BaseRequest<NormalRepayContract.View> implements NormalRepayContract.Presenter<NormalRepayContract.View> {

    public static NormalRepayRequest create() {
        return new NormalRepayRequest();
    }


    @Override
    public void getNormalRepay(String id, String keys) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        NormalRepayBean bean = new NormalRepayBean();
        bean.deal_id = id;
        bean.keys = keys;
        Api.api_service.getNormalRepay(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.getStatus() ==1) {
                        mView.getNormalRepaySuccess(result);
                    } else {
                        mView.getNormalRepayFail(result.getMsg());
                    }

                });
    }
}
